package me.mystream.streamdemo;

import java.util.ArrayList;
import java.util.Collections;
import java.util.stream.Stream;

public class StreamDemo5 {
    public static void main(String[] args) {
        //Stream流的中间方法
        ArrayList<String> list1 = new ArrayList<>();
        Collections.addAll(list1, "张无忌", "赵敏", "张亮", "张三丰", "谢广坤");

        //方法一
        //过滤器
        //list1.stream().filter(s -> s.startsWith("张")).forEach(s -> System.out.println(s));
        //limit,获取前几个元素
        //list1.stream().limit(2).forEach(s -> System.out.println(s));
        //skip，跳过几个元素
        //list1.stream().skip(3).forEach(s -> System.out.println(s));
        ArrayList<String> list2 = new ArrayList<>();
        Collections.addAll(list2, "张强", "张翠山", "张强");
        //元素去重
        //如果是自定义类型，需要重写equals和hashCode方法
        //list2.stream().distinct().forEach(s -> System.out.println(s));

        //合并两个流
        Stream.concat(list1.stream(), list2.stream()).forEach(s -> System.out.println(s));
    }
}
